<?php
namespace app\admin\controller;

use think\Db;

/**
 * 前台栏目页面展示
 * Class SolutionController
 * @package app\admin\controller
 */
class SpecialController extends CommonController
{
    //1.心智习惯
    public function habitsofmind()
    {
        //获取父级类的内容
        $data = $this->common_block('habitsofmind');
        if (request()->isPost()) {
            if ($data === false) {
                $this->error('修改失败，请稍后重试');
            }else {
                $this->success('修改成功');
            }
        }
        $this->assign('data', $data);
        return $this->fetch();
    }
    //2.教育团队
    public function team()
    {
        if (request()->isPost()) {
            $data = input('post.');
            //$data = array_filter($data);
            //去除数组中的空值
            foreach ($data as $k=>$v) {
                if (is_array($v)) {
                    $data[$k] = array_filter($v);
                }
            }

            $str = serialize($data);
            //dump($str);
            $rs = Db::name('block')->where('type','team')->update(['content' => $str]);
            if ($rs === false) {
                $this->error('修改失败，请稍后重试');
            }else {
                $this->success('修改成功');
            }
        }
        //获取首页区块内容
        $content = Db::name('block')->field('content')->where('type', 'team')->find();
        //反序列化 数据
        $data = unserialize($content['content']);

        $i = count($data['img_url']);
        $m = count($data['url']);
        $this->assign('data', $data);
        $this->assign('i', $i+1);
        $this->assign('m', $m+1);
        return $this->fetch();
    }
    //3.特色课程
    public function programs()
    {
        //获取父级类的内容
        $data = $this->common_block('programs');
        if (request()->isPost()) {
            if ($data === false) {
                $this->error('修改失败，请稍后重试');
            }else {
                $this->success('修改成功');
            }
        }
        $this->assign('data', $data);
        return $this->fetch();
    }
    //4.创设环境
    public function environment()
    {
        //获取父级类的内容
        $data = $this->common_block('environment');
        if (request()->isPost()) {
            if ($data === false) {
                $this->error('修改失败，请稍后重试');
            }else {
                $this->success('修改成功');
            }
        }

        $this->assign('data', $data);
        return $this->fetch();
    }
}
